package util.seungha;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.util.Log;
import android.widget.TextView;

public class EffectView extends CountDownTimer 
{
	
	static final int TIME_DEFAULT_TOTAL		= 1000*60*60*24;
	static final int TIME_DEFAULT_INTERVAL	= 100;
	
	static final int COLOR_MASK_ALPHA	= 0xFF000000;
	static final int COLOR_MASK_RED		= 0x00FF0000;
	static final int COLOR_MASK_GREEN	= 0x0000FF00;
	static final int COLOR_MASK_BLUE	= 0x000000FF;
	
	static final int ALPHA_MAX	= 0xFF000000;
	static final int ALPHA_MIN	= 0x3F000000;
	
	static final int ALPHA_OPERATION_VALUE	= 0x10000000;
	
	int mCounter;
	int mColor;
	
	boolean mIncrease_Alpha;
	boolean mIncrease_TextSize;
	
	TextView mEffectView;

	public EffectView(TextView tv, int color) 
	{
		super(TIME_DEFAULT_TOTAL, TIME_DEFAULT_INTERVAL);
		
		if(tv == null)return;
		
		this.mEffectView 	= tv;
		this.mCounter 		= 0;
		this.mIncrease_Alpha		= true;
		
		switch(color)
		{
			case Color.WHITE:
			case Color.RED:
			case Color.YELLOW:
			case Color.GREEN:
			case Color.BLUE:
			{
				this.mColor = color;
				break;
			}
			default:
			{
				this.mColor = Color.WHITE;
				break;
			}
		}
		
		
	}

	@Override
	public void onFinish() 
	{
		// TODO Auto-generated method stub
		super.cancel();
	}

	@Override
	public void onTick(long millisUntilFinished) 
	{
		
		int	aValue;
/*		
		int	rValue;
		int	gValue;
		int	bValue;
		rValue = currColor & COLOR_MASK_RED;
		gValue = currColor & COLOR_MASK_GREEN;
		bValue = currColor & COLOR_MASK_BLUE;
*/
		
		aValue 		= this.mColor & COLOR_MASK_ALPHA;

		//Log.i("DBG", "[EffectView]onTick"+" this.mColor:"+this.mColor);		
		
		if(aValue == ALPHA_MAX)this.mIncrease_Alpha = false;
		if(aValue == ALPHA_MIN)this.mIncrease_Alpha = true;

		
		if(this.mIncrease_Alpha == true)this.mColor += ALPHA_OPERATION_VALUE;
		else 							this.mColor	-= ALPHA_OPERATION_VALUE;
		
		this.mEffectView.setTextColor(this.mColor);

/*		
		{
			float textSize_Current;
			float OperlationSize = +1;
	
			textSize_Current = this.mEffectView.getTextSize();
			Log.i("DBG", "[EffectView]onTick"+" textSize_Current:"+textSize_Current);
			
			
			if(textSize_Current >= 50)mIncrease_TextSize = false;;
			if(textSize_Current <= 1) mIncrease_TextSize = true;
			
			if(mIncrease_TextSize == true)this.mEffectView.setTextSize(textSize_Current+1);
			else						  this.mEffectView.setTextSize(textSize_Current-1);
		}
*/		
	}

}
